<?php
$cart = new BWCart();
$view = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Paid)));
$control3 = new BUIControl('cancelPaidBooking');
$control2 = new BUIControl('showBookingDetail');
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll3").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>

<legend>
    <?php echo '我的预订记录'; ?>|<small>
        <?php
        echo $control->getAjaxLink(array(
            'name' => '我的未支付订单',
            'id' => 'showMyBookingList'), array(
            'paymentStatus' => 'unpaid'));
        ?></small>
</legend>

<table class="table table-hover">
    <thead>
        <tr>
            <th>
                <input type="checkbox"  id="selectAll3"> 
            </th>
            <th><?php echo '序号'; ?></th>
            <th><?php echo '交易号'; ?></th>
            <th><?php echo '订单号'; ?></th>
            <th><?php echo '产品号'; ?></th>
            <th><?php echo '金额（元）'; ?></th>
            <th><?php echo '付款时间'; ?></th>
        </tr> 
    </thead>
    <fieldset>
        <tbody>
            <?php
            $totalMoney = 0;
            $serial = 0;
            $bookingTable = new BTreeTable('BWInputValue');
            foreach ($view as $cartList) {
                if ($cartList instanceof BTreeList) {
                    $serial++;
                    $cartId = $cartList->getId();
                    $transactionId = $cartList->getItem('transactionId')->value;
                    $price = $cartList->getItem('price')->value;
                    $unit = $cartList->getItem('moneyUnit')->value;
                    $quantity = $cartList->getItem('quantity')->value;
                    $productName = $cartList->getItem('productName')->value;
                    $productId = $cartList->getItem('productId')->value;
                    $paidMoney = $price * $quantity;
                    $paidTime = $cartList->getItem('paidTime')->value;
                    $paidTimeString = date('Ymd G:i:s', $paidTime);
                }
                ?>
                <tr>

                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $cartId; ?>"> 
                        </label></td>
                    <td> <?php echo $serial; ?> </td>
                    <td> <?php echo $transactionId; ?> </td>
                    <td> <?php echo $cartId; ?> </td>
                    <td> <?php echo $productId; ?> </td>      
                    <td> <?php echo $paidMoney; ?> </td>   
                    <td> <?php echo $paidTimeString; ?> </td>   
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            $bookingRow = $bookingTable->getListById($productId);
                            $startTime = $bookingRow->getItem('startTime')->value;
                            $cancelTime = $bookingRow->getItem('bookingCancelTime')->value;
                            echo $control2->getAjaxLink(array('name' => '查看', 'id' => 'showBookingDetail'), array(
                                'cartId' => $cartId,
                                'bookingId' => $productId,
                                //'ajaxContainerId' => 'myModal2',
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data',
                                ),
                                'ajaxOptions' => array(
                                    'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal2").modal("show");}')
                            ));
                            //if can cancel one day before
                            if ($cancelTime > time()) {
                                echo " | ";
                                echo $control3->getAjaxLink(array('name' => '取消预订', 'id' => 'cancelPaidBooking'), array(
                                    'cartId' => $cartId,
                                    'bookingId' => $productId,
                                    //'ajaxContainerId' => 'myModalContent',
                                    'htmlOptions' => array(
                                        'enctype' => 'multipart/form-data',
                                    ),
                                    'ajaxOptions' => array(
                                        'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal").modal("show");}')
                                ));
                            }
                            ?>   
                        </div>                      
                    </td>
                </tr>
            <?php } ?>          
        </tbody>
    </fieldset>
</table>


<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">    
    <div id="myModalContent" class="modal-body" >
        <?php $control3->render(); ?>
    </div>
    <div class = "modal-footer">
        <?php
        $data = array();
        $data['htmlOptions'] = array('class' => 'btn', 'data-dismiss' => 'modal', 'aria-hidden' => 'true');
        $data['paymentStatus'] = 'paid';
        echo $control->getAjaxLink(array('name' => '关闭', 'id' => 'showMyBookingList'), $data);
        ?>
    </div>
</div>
<div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">    
    <?php $control2->render(); ?>
</div>

<div><input type="hidden" name="curPageNo" value="1"></div>

<div class="pagination">  
    <ul>  
        <li class="active">
            <a href="javascript:void()">前一页</a>    </li>  
        <li class="active">
            <a href="javascript:void()">1</a>    </li>  
        <li class="active">
            <a href="javascript:void()">后一页</a>    </li>  
    </ul>  
</div>
